package main

import (
	"fmt"
	"net/http"
	"os"
	"user/config"
	"user/logger"
	"user/router"
)

func main() {
	driverName := "mysql"
	dsn := "golang:zxc,./123@tcp(43.139.115.142:3306)/user?charset=utf8mb4&loc=Local&parseTime=true"

	err := config.InitDb(driverName, dsn)
	if err != nil {
		fmt.Println(err)
		return
	}
	defer config.CloseDB()
	router.RegisterRouters()

	logfile, err := os.OpenFile("log/access.log", os.O_APPEND|os.O_CREATE|os.O_WRONLY, os.ModePerm)
	if err != nil {
		fmt.Println("日志文件打开错误", err)
		return
	}
	logger.InitLogger(logfile)
	http.ListenAndServe(":19999", nil)
}
